<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页留言板</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
        }
        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            max-width: 1400px;
            padding: 20px;
            background: #fff;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
            border-radius: 12px;
            overflow: hidden;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
            width: 100%;
        }
        .header h1 {
            color: #2c3e50;
            margin-bottom: 10px;
        }
        .stats {
            display: flex;
            justify-content: space-around;
            width: 100%;
            margin-bottom: 20px;
            background: #f9f9f9;
            padding: 15px;
            border-radius: 10px;
            box-shadow: 0 0 8px rgba(0, 0, 0, 0.05);
        }
        .stat-item {
            text-align: center;
        }
        .stat-value {
            font-size: 24px;
            font-weight: bold;
            color: #3498db;
        }
        .stat-label {
            font-size: 14px;
            color: #7f8c8d;
        }
        .input-section {
            width: 100%;
            max-width: 800px;
            margin-bottom: 25px;
            background: #f9f9f9;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.08);
            transition: box-shadow 0.3s ease;
        }
        .input-section:hover {
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
        }
        .board-selector {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
            align-items: center;
        }
        .board-selector select {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            background-color: #fff;
            color: #333;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            flex-grow: 1;
            margin-left: 10px;
        }
        .board-selector select:hover {
            background-color: #e8f4fc;
            border-color: #3498db;
        }
        .input-section textarea {
            width: 100%;
            max-width: 100%;
            margin-bottom: 15px;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            color: #333;
            resize: none;
            transition: border-color 0.3s ease;
            font-family: Arial, sans-serif;
        }
        .input-section textarea:focus {
            border-color: #3498db;
            outline: none;
            box-shadow: 0 0 5px rgba(52, 152, 219, 0.5);
        }
        .input-section button {
            padding: 10px 20px;
            background-color: #3498db;
            color: #fff;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }
        .input-section button:hover {
            background-color: #2980b9;
        }
        .filter-section {
            width: 100%;
            margin-bottom: 20px;
            display: flex;
            justify-content: center;
        }
        .filter-section input {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            width: 70%;
            max-width: 500px;
        }
        .boards {
            display: flex;
            justify-content: space-around;
            width: 100%;
            max-width: 1200px;
            flex-wrap: wrap;
        }
        .board {
            flex: 1;
            min-width: 300px;
            margin: 10px;
            background: #f9f9f9;
            border: 1px solid #e0e0e0;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.06);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .board:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .board h2 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid #3498db;
        }
        .board .messages {
            max-height: 400px;
            overflow-y: auto;
            padding: 10px;
            background-color: #edf7fd;
            border: 1px solid #c6e3f6;
            border-radius: 8px;
        }
        .board .message {
            padding: 12px;
            margin-bottom: 12px;
            background-color: #fff;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            font-size: 14px;
            color: #333;
            transition: background-color 0.3s ease;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            flex-direction: column;
        }
        .board .message:hover {
            background-color: #f5f9ff;
        }
        .message-content {
            margin-bottom: 8px;
            width: 100%;
        }
        .message-time {
            font-size: 12px;
            color: #7f8c8d;
            margin-bottom: 8px;
        }
        .message-actions {
            display: flex;
            justify-content: space-between;
            width: 100%;
        }
        .board .message button {
            padding: 5px 10px;
            background-color: #e74c3c;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 12px;
            transition: background-color 0.3s ease;
        }
        .board .message button:hover {
            background-color: #c0392b;
        }
        .board .messages::-webkit-scrollbar {
            width: 8px;
        }
        .board .messages::-webkit-scrollbar-thumb {
            background-color: #a0d0f8;
            border-radius: 4px;
        }
        .board .messages::-webkit-scrollbar-track {
            background-color: #f1f1f1;
            border-radius: 4px;
        }
        @media (max-width: 900px) {
            .boards {
                flex-direction: column;
            }
            .board {
                min-width: auto;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>多功能留言板系统</h1>
    </div>
    
    <div class="stats">
        <div class="stat-item">
            <div class="stat-value" id="totalMessages">0</div>
            <div class="stat-label">总留言数</div>
        </div>
        <div class="stat-item">
            <div class="stat-value" id="todayMessages">0</div>
            <div class="stat-label">今日留言</div>
        </div>
        <div class="stat-item">
            <div class="stat-value" id="storageUsage">0KB</div>
            <div class="stat-label">存储使用</div>
        </div>
    </div>
    
    <div class="input-section">
        <div class="board-selector">
            <label for="boardSelect">选择留言板：</label>
            <select id="boardSelect">
                <option value="board1">留言板1</option>
                <option value="board2">留言板2</option>
                <option value="board3">留言板3</option>
            </select>
        </div>
        <form id="messageForm">
            <textarea id="messageInput" placeholder="请输入留言..." rows="4"></textarea>
            <button type="submit">提交留言</button>
        </form>
    </div>
    
    <div class="filter-section">
        <input type="text" id="filterInput" placeholder="搜索留言...">
    </div>
    
    <div class="boards">
        <div class="board" id="board1">
            <h2>留言板1</h2>
            <div class="messages" id="messages1"></div>
        </div>
        <div class="board" id="board2">
            <h2>留言板2</h2>
            <div class="messages" id="messages2"></div>
        </div>
        <div class="board" id="board3">
            <h2>留言板3</h2>
            <div class="messages" id="messages3"></div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const messageForm = document.getElementById('messageForm');
        const messageInput = document.getElementById('messageInput');
        const boardSelect = document.getElementById('boardSelect');
        const filterInput = document.getElementById('filterInput');
        const totalMessagesEl = document.getElementById('totalMessages');
        const todayMessagesEl = document.getElementById('todayMessages');
        const storageUsageEl = document.getElementById('storageUsage');
        
        const boards = ['board1', 'board2', 'board3'];
        const allBoards = JSON.parse(localStorage.getItem('allBoards')) || {
            board1: [],
            board2: [],
            board3: []
        };

        // 初始化统计信息
        function updateStats() {
            // 计算总留言数
            let total = 0;
            boards.forEach(board => {
                total += allBoards[board].length;
            });
            totalMessagesEl.textContent = total;
            
            // 计算今日留言
            const today = new Date().toDateString();
            let todayCount = 0;
            boards.forEach(board => {
                allBoards[board].forEach(msg => {
                    if (msg.time && new Date(msg.time).toDateString() === today) {
                        todayCount++;
                    }
                });
            });
            todayMessagesEl.textContent = todayCount;
            
            // 计算存储使用
            const data = localStorage.getItem('allBoards');
            const size = data ? new Blob([data]).size : 0;
            storageUsageEl.textContent = Math.round(size / 1024) + 'KB';
        }

        // 显示所有留言板的留言
        function displayMessages(filterText = '') {
            boards.forEach(board => {
                const messagesDiv = document.getElementById(`messages${board.slice(-1)}`);
                const messages = allBoards[board];
                messagesDiv.innerHTML = '';
                
                messages.forEach((message, index) => {
                    // 应用过滤器
                    if (filterText && !message.text.toLowerCase().includes(filterText.toLowerCase())) {
                        return;
                    }
                    
                    const messageElement = document.createElement('div');
                    messageElement.classList.add('message');
                    
                    const time = message.time ? new Date(message.time).toLocaleString() : '时间未知';
                    
                    messageElement.innerHTML = `
                        <div class="message-content">${message.text}</div>
                        <div class="message-time">${time}</div>
                        <div class="message-actions">
                            <span>留言 #${index + 1}</span>
                            <button class="delete-button" data-board="${board}" data-index="${index}">删除</button>
                        </div>
                    `;
                    messagesDiv.appendChild(messageElement);
                });
            });
            
            updateStats();
        }

        // 初始化时显示所有留言板的留言
        displayMessages();

        // 提交留言
        messageForm.addEventListener('submit', (e) => {
            e.preventDefault();
            const messageText = messageInput.value.trim();
            if (messageText) {
                const currentBoard = boardSelect.value;
                allBoards[currentBoard].push({
                    text: messageText,
                    time: new Date().toISOString()
                });
                localStorage.setItem('allBoards', JSON.stringify(allBoards));

                // 更新显示
                displayMessages();
                messageInput.value = '';
            }
        });

        // 监听删除按钮的点击事件
        document.addEventListener('click', (e) => {
            if (e.target.classList.contains('delete-button')) {
                const board = e.target.getAttribute('data-board');
                const index = e.target.getAttribute('data-index');
                allBoards[board].splice(index, 1);
                localStorage.setItem('allBoards', JSON.stringify(allBoards));
                displayMessages(filterInput.value);
            }
        });

        // 监听过滤输入
        filterInput.addEventListener('input', (e) => {
            displayMessages(e.target.value);
        });
        
        // 初始化统计信息
        updateStats();
    });
</script>
</body>
</html>